/*
* @Author: sc
* @Date:   2019-01-10 11:25:53
* @Last Modified by:   sc
* @Last Modified time: 2019-01-14 00:54:22
*/
import { observable, computed, action, configure } from 'mobx';

configure({
    enforceActions : "always"
});

class Todo{
    @observable content  = {};
    @observable finished = false;
    @observable deleted  = false;
    @observable editStatus  = 'not-edit';

    constructor(id, data) {
    	// 将data转换为json数据存储，并添加序号和时间
		let	result = {
				'id'    : id,
				'data'  : data,
				'ctime' : new Date().toLocaleString(),
				'dtime' : '',
                'status': '未完成'
		};
        this.content = result;
    }
    
    @action changeEditStatus = () => {
        if(this.editStatus === 'not-edit'){
            this.editStatus = 'edit';
        }
        else if(this.editStatus === 'edit'){
            this.editStatus = 'not-edit';
        }
    }
    @action editText = (data) => {
        this.content.data = data;
        this.content.ctime = new Date().toLocaleString();
    }
    // 完成标志为true
    @action finish = () => {
      this.finished       = true;
	  this.content.dtime  = new Date().toLocaleString();
      this.content.status = '已完成' ;
    }
    // 删除标志为true
    @action delete  = () => {
      this.deleted  = true;
    }

}

export default Todo;